#ifndef H264DECSDK_H
#define H264DECSDK_H

#ifdef __cplusplus
extern "C" {
#endif 

//the h264 decode session idenfier type
typedef int H264DECSESSION;

#define DLLSPEC __declspec(dllimport)

//Create a new h264 decode session with the specific video size.
//parameters:
//streambased - set to non-zero if the data send to the decoder is a bitstream not frames
//return value:
//a non-zero H264DECSESSION value if a new decode session was created,
//or 0 if the video size is invalid.
DLLSPEC H264DECSESSION __cdecl CreateDecodeSession(unsigned int width, unsigned int height, int streambased);

//Create a new h264 decode session,the video size will be decided by the decoder while decoding.
//parameters:
//streambased - set to non-zero if the data send to the decoder is a bitstream not frames
//return value:
//a non-zero H264DECSESSION value if a new decode session was created,
//or 0 if failed.
DLLSPEC H264DECSESSION __cdecl CreateDecodeSessionNoSize(int streambased);

//Close a decode session,all resources of the session will be released.
DLLSPEC void __cdecl CloseDecodeSession(H264DECSESSION);

//Close all decode sessions.
DLLSPEC void __cdecl ClearAllSession();

//get video size relative to the decode session.
//parameters:
//session - the session identiier
//width - address of a integer value for the output video width 
//height - address of a integer value for the output video height 
//return value:
//0 - the video size of the session has been set.
//-1 - invalid session
//-2 - the video size has not been set yet.
//-3 - at least one of the parameters for output is null
DLLSPEC int __cdecl GetVideoSize(H264DECSESSION session, int *width, int *height);


//Decode h264 stream data,the output format is yuv420p.
//parameters:
//session - the session identiier
//inbuf - the address of h264 stream data to be decoded
//size - the size of h264 video stream data
//getframe - address to a integer value,the value will be set to non-zero if a new frame is decoded during this call,or set to 0 if still need more data for a new frame
//ybuf - the address to output buffer of y channel of decoded frame.it must not be null.
//ubuf - the address to output buffer of u channel of decoded frame it must not be null.
//vbuf - the address to output buffer of v channel of decoded frame it must not be null.
//dstlinesize - the output buffer line size.
//              you may set a different line size which must be larger than width of frame,or 0 to use the width of frame.
//              the line size of ubuf and vbuf will be the half of it.
//reverse - set to non-zero if you want to output the decoded frame upside down,or else set to 0.
//
//Return value:
//a positive integer indicates how many bytes was decoded if the frame was decoded successfully,
//or a negative integer error number in the following list.Check getframe to see if a new frame decoded.
//-1 - can not find the decode session width the specific H264DECSESSION value.
//-2 - encounters an error while decoding
//-4 - the dstlinesize small than frame width
//-5 - one of the output buffer addresses is null
//-6 - the address to h264 frame data is null,or size is 0.
//-7 - getframe is a null pointer
DLLSPEC int __cdecl DecodeData(H264DECSESSION session, unsigned char *inbuf, unsigned int size, 
							   int *getframe,
								unsigned char *ybuf, unsigned char *ubuf, unsigned char *vbuf,
								int dstlinesize, int reverse);

//Decode a h264 frame,the output format is yuv420p.
//parameters:
//session - the session identiier
//inbuf - the address of h264 video frame data
//size - the size of h264 video frame data
//ybuf - the address to output buffer of y channel of decoded frame.it must not be null.
//ubuf - the address to output buffer of u channel of decoded frame it must not be null.
//vbuf - the address to output buffer of v channel of decoded frame it must not be null.
//dstlinesize - the output buffer line size.
//              you may set a different line size which must be larger than width of frame,or 0 to use the width of frame.
//              the line size of ubuf and vbuf will be the half of it.
//reverse - set to non-zero if you want to output the decoded frame upside down,or else set to 0.
//
//Return value:
//a positive integer indicates how many bytes was decoded if the frame was decoded successfully,
//or a negative integer error number in the following list.
//-1 - can not find the decode session width the specific H264DECSESSION value.
//-2 - encounters an error while decoding
//-3 - the input data not a full h264 frame
//-4 - the dstlinesize small than frame width
//-5 - one of the output buffer addresses is null
//-6 - the address to h264 frame data is null,or size is 0.
DLLSPEC int __cdecl DecodeFrame(H264DECSESSION session, unsigned char *inbuf, unsigned int size, 
						unsigned char *ybuf, unsigned char *ubuf, unsigned char *vbuf,
						int dstlinesize, int reverse);

#ifdef __cplusplus
}
#endif

#endif 